package com.example.comm.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.comm.Bean.User;
import com.example.comm.R;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;

public class MyInfo extends AppCompatActivity {
    private ImageView back;
    private TextView my_name,my_pushnum,my_comnum;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myinfo);
        initView();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //获取信息
        getInfo();
    }

    private void getInfo() {
        User user=BmobUser.getCurrentUser(User.class);
        String Id=user.getObjectId();
        BmobQuery<User> bmobQuery=new BmobQuery<User>();
        bmobQuery.getObject(Id, new QueryListener<User>() {
            @Override
            public void done(User user, BmobException e) {
                if(e==null){
                    my_name.setText(user.getUsername());
                    //nickname.setText(user.getNickname());
                }else{
                    Toast.makeText(MyInfo.this, "加载失败", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }

    private void initView() {
        back=findViewById(R.id.back);
        my_name=findViewById(R.id.my_name);
        my_comnum=findViewById(R.id.my_comnum);
        my_pushnum=findViewById(R.id.my_pushnum);
    }
}
